import java.util.Scanner;

class FootballClub {
    String name;           // 俱乐部名称
    int matchesPlayed;     // 已比赛的场数
    int wins;              // 赢的场数
    int draws;             // 平的场数
    int losses;            // 负的场数
    int goalsFor;          // 进球数
    int goalsAgainst;      // 失球数
    int points;            // 积分

    // 构造函数
    public FootballClub(String name) {
        this.name = name;
        this.matchesPlayed = 0;
        this.wins = 0;
        this.draws = 0;
        this.losses = 0;
        this.goalsFor = 0;
        this.goalsAgainst = 0;
        this.points = 0;
    }

    // 更新比赛结果
    public void updateMatch(int goalsFor, int goalsAgainst) {
        this.matchesPlayed++;
        this.goalsFor += goalsFor;
        this.goalsAgainst += goalsAgainst;

        if (goalsFor > goalsAgainst) {
            this.wins++;
            this.points += 3;  // 胜利得3分
        } else if (goalsFor < goalsAgainst) {
            this.losses++;
        } else {
            this.draws++;
            this.points += 1;  // 平局得1分
        }
    }

    // 计算净胜球
    public int goalDifference() {
        return this.goalsFor - this.goalsAgainst;
    }

    // 输出俱乐部信息
    public void printClubInfo() {
        System.out.printf("%-15s %2d %2d %2d %2d %3d %3d %3d\n",
                name, matchesPlayed, wins, draws, losses, goalsFor, goalsAgainst, points);
    }

    // 排序依据：积分 > 净胜球 > 进球数
    public static int compare(FootballClub c1, FootballClub c2) {
        if (c1.points != c2.points) {
            return Integer.compare(c2.points, c1.points);  // 积分多者排前
        }
        if (c1.goalDifference() != c2.goalDifference()) {
            return Integer.compare(c2.goalDifference(), c1.goalDifference());  // 净胜球多者排前
        }
        return Integer.compare(c2.goalsFor, c1.goalsFor);  // 进球数多者排前
    }
}

public class FootballLeague {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 示例：创建足球俱乐部（这里假设俱乐部数为4个）
        FootballClub[] clubs = new FootballClub[4];
        clubs[0] = new FootballClub("ClubA");
        clubs[1] = new FootballClub("ClubB");
        clubs[2] = new FootballClub("ClubC");
        clubs[3] = new FootballClub("ClubD");

        // 输入并更新比赛结果
        System.out.println("请输入比赛结果（格式：主队名 客队名 主队得分 客队得分）：");
        while (true) {
            String line = scanner.nextLine();
            if (line.trim().isEmpty()) {
                break;  // 空行结束输入
            }

            String[] match = line.split(" ");
            String homeClubName = match[0];
            String awayClubName = match[1];
            int homeGoals = Integer.parseInt(match[2]);
            int awayGoals = Integer.parseInt(match[3]);

            // 查找主队和客队
            FootballClub homeClub = null, awayClub = null;
            for (FootballClub club : clubs) {
                if (club.name.equals(homeClubName)) {
                    homeClub = club;
                } else if (club.name.equals(awayClubName)) {
                    awayClub = club;
                }
            }

            // 更新比赛结果
            if (homeClub != null && awayClub != null) {
                homeClub.updateMatch(homeGoals, awayGoals);
                awayClub.updateMatch(awayGoals, homeGoals);
            } else {
                System.out.println("未找到相关俱乐部，继续输入...");
                continue;
            }
        }

        // 排序
        java.util.Arrays.sort(clubs, FootballClub::compare);

        // 输出结果
        System.out.println("\n比赛后的积分榜：");
        System.out.println("俱乐部名称       场数  胜  平  负  进球  失球  积分");
        for (FootballClub club : clubs) {
            club.printClubInfo();
        }

        scanner.close();
    }
}